<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="d" uri="/WEB-INF/resource.tld" %>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>

  <title></title>

</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>

  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">

    <div class="panel panel-default x-panel x-panel-layout">

      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/ecommerce">电商管理</a></li>
          <li class="active">优惠券管理</li>
          <li class="no-before pull-right" style="min-width: 65px;">
            <a onclick="window.history.back();"><i class="glyphicon glyphicon-arrow-left"></i>&nbsp;&nbsp;返回</a>
          </li>
        </ol>
      </div>

      <div class="panel-body">

        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">

          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire" title="批次详情"></i>&nbsp;&nbsp;<span>优惠券管理&nbsp;-&nbsp;批次详情</span></h2>
            </div>
          </div>
          
          <div class="x-breadcrumb-wrapper" style="margin-top: 20px;">
            <div class="x-breadcrumb yellow clearfix">
              <h2><span>基本信息</span></h2>
              <c:if test="${currentPrincipal.admin or currentPrincipal.root}">
                <a href="${ctx.host}/coupon-batches/${couponBatch.id}/edit" data-toggle="modal" data-target="#coupon-batch-edit" dataclass="hover-no-text-decoration" style="position: absolute; right: 0px; top: 0px; margin-top: 10px; margin-right: 10px;" title="编辑信息">编辑信息</a>
              </c:if>
            </div>
          </div> 
          
          <div class="form-horizontal" style="margin-top: 20px;">
            <div class="form-group">
              <label class="control-label col-xs-2">优惠券名称：</label>
              <div class="col-xs-4 pull-left">
                <p class="form-control-static">${couponBatch.templateName}</p>
              </div>
              
              <label class="control-label col-xs-2">批次名称：</label>
              <div class="col-xs-4 pull-left">
                <p class="form-control-static">${couponBatch.name}</p>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-xs-2">本次发放总数：</label>
              <div class="col-xs-4 pull-left">
                <p class="form-control-static">${couponBatch.amount}</p>
              </div>
              <label class="control-label col-xs-2">已使用数：</label>
              <div class="col-xs-4 pull-left">
                <p class="form-control-static">${couponBatch.usedAmount}</p>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-xs-2">已认领数：</label>
              <div class="col-xs-4 pull-left">
                <p class="form-control-static">${couponBatch.claimedAmount}</p>
              </div>
              <label class="control-label col-xs-2">截止日类型：</label>
              <div class="col-xs-4 pull-left">
                <p class="form-control-static">${couponBatch.expireType.description}</p>
              </div>
            </div>
            <c:if test="${couponBatch.expireType eq 'FIXED_DATE' }">
              <div class="form-group">
                <label class="control-label col-xs-2">开始日期：</label>
                <div class="col-xs-4 pull-left">
                  <p class="form-control-static">
                    <fmt:formatDate value="${couponBatch.effectiveStartDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                  </p>
                </div>
                <label class="control-label col-xs-2">截止日期：</label>
                <div class="col-xs-4 pull-left">
                  <p class="form-control-static">
                    <fmt:formatDate value="${couponBatch.effectiveEndDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                  </p>
                </div>
              </div>
            </c:if>
          </div>
          
          <div class="form-horizontal"  style="margin-top:20px;">
            <div class="x-breadcrumb-wrapper">
              <ul class="nav nav-pills x-breadcrumb-nav">
                <li class="pull-left active"><a href="javascript: void(0)">优惠券列表</a></li>
              </ul>
            </div>

            <table class="table table-striped table-hover x-table" style="margin-bottom:20px;">
              <thead>
                <tr>
                  <th>券码</th>
                  <th>开始日期</th>
                  <th>截止日期</th>
                  <th>状态</th>
                  <th>用户</th>
                  <th>实际抵扣金额</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
                <c:forEach var="coupon" items="${coupons}">
                  <tr>
                    <td>${coupon.code}</td>
                    <td><fmt:formatDate value="${coupon.effectiveStartDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                    <td><fmt:formatDate value="${coupon.effectiveEndDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                    <td><span class="label label-${coupon.status.css}">${coupon.status.description}</span></td>
                    <td>${persist.user(coupon.userId).profile.nickname}&nbsp;-&nbsp;${coupon.identification}</td>
                    <td>${coupon.amount/100}元</td>
                    <td class="text-center">
                      <c:choose>
                        <c:when test="${coupon.status.isUnclaimed() and (currentPrincipal.admin or currentPrincipal.root)}">
                          <a href="${ctx.host}/coupon-batches/${couponBatch.id}/coupons/${coupon.id}/identify" data-target="#coupon-batch-identify" data-toggle="modal" title="指定用户">指定用户</a>
                        </c:when>
                        <c:otherwise>无</c:otherwise>
                      </c:choose>
                    </td>
                  </tr>
                </c:forEach>
              </tbody>
            </table>
            
            <jsp:include page="/WEB-INF/include/page.jsp">
              <jsp:param name="url" value="coupon-batches/${couponBatch.id}" />
            </jsp:include>
          </div>
        </div>
        
      </div>
      
    </div>
    
  </div>

  <%@ include file="/WEB-INF/include/footer.jsp"%>
  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/encommerce/coupon/coupon-batch-view.js">
    <script type="text/javascript">
      require(['page/encommerce/coupon/coupon-batch-view'], function(page) {
        page.init()
      })
    </script>
  </d:resource>
  
</body>

</html>